// VC70SocketThread.h: interface for the CVC70SocketThread class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(VC70SOCKETTHREAD_H)
#define VC70SOCKETTHREAD_H

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "../Common/RMSThread.h"
#include "../RMSLib/clientinterface.h"

BOOL operator < (const TimeMark& tm1, const TimeMark& tm2);

class CVC70SocketThread : public CRMSThread,
						  public ClientAccess
{
public:
	CInfo m_info;
	int m_nCurrentFrameRate;
	int m_nBitrate;

	TimeMark m_timeStart;
	TimeMark m_timeEnd;

	char m_szTime[50];
	char m_szDate[50];

	int m_nCamera;
	BOOL m_bStored;
	DWORD m_frames;

#ifdef _JNC_REC_
	TimeMark m_timeFrom;
	TimeMark m_timeTo;
	BOOL m_bGetRecords;
#endif //def _JNC_REC_

	CVC70SocketThread();
	virtual ~CVC70SocketThread();
	void UpdateStatus(BYTE status, DWORD code = 0L);// show socket status
	void CloseSocket(BOOL bShowStatus = TRUE);
	void ShowSockError(HWND wnd, const char* msg, const char* IP);

	DWORD OnTerminate();
	void OnCriticalTerminate();
	BOOL Execute();
	void resetStoredVideo();

	void reformatCallString(LPSTR str, CInfo* info);

protected:
	SOCKET m_Socket;
	sockaddr_in m_sa;
	FILE* m_file;
	CSingleLock *slFile;

	BYTE* m_pData;
	BYTE m_AudioData[0x20000];

	DWORD ThreadFunc();
	
	BOOL TAGReceive();
	BOOL TAGRequest();
	DWORD RequestFormat();
	DWORD tcpRing();

	int ReceiveData(SOCKET* Socket, void* data, int Len);
private:
	BOOL TestDiskSpace();
	void	closeChannel();
	BOOL bindSocket(DWORD addr, int nTCPPort = 777);
	BOOL connectToServer(DWORD addr, int port);
	long m_lTotalReceivedData;
	DWORD m_dwCountByte;

	int m_nUDPServerPort;

	DWORD timeBegin;
	DWORD timeEnd;
	DWORD timeFrame;
	DWORD dwDelta;
	int nFPS;

	char m_szBuffer[255];

	__int64 m_i64FreeBytesToCaller;
	__int64 m_i64TotalBytes;
	__int64 m_i64FreeBytes;

	DWORD m_dwSectPerClust;
	DWORD m_dwBytesPerSect;
	DWORD m_dwFreeClusters;
	DWORD m_dwTotalClusters;

	BOOL m_bDecode;
	BOOL m_bSupportRing;
};

#endif // !defined(VC70SOCKETTHREAD_H)
